<!--
 * @Author: likaijie 847094299@qq.com
 * @Date: 2025-04-07 10:15:03
 * @LastEditors: 深海有鱼 847094299@qq.com
 * @LastEditTime: 2025-08-24 19:16:13
 * @Description: 
-->
<template>
  <div class="provider-usage-page">
    <div>
      <el-button type="primary" @click="fetchUsage">刷新</el-button>
    </div>
    <el-table
      show-overflow-tooltip
      stripe
      border
      :data="usageData"
      style="width: 100%"
    >
      <el-table-column prop="provider" label="提供商" />
      <el-table-column prop="count" label="调用次数" />
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { ElMessage } from "element-plus";
import { getAllProviders } from "@/api/adminProvidersApi";

interface ProviderUsage {
  id: number;
  providerName: string;
  callCount: number;
  avgResponseTime: number;
}

const usageData = ref<ProviderUsage[]>([]);

async function fetchUsage() {
  try {
    const { success, data, message } = await getAllProviders();
    if (success) {
      usageData.value = data;
    } else {
      ElMessage.error(message || "获取使用情况失败");
    }
  } catch (error) {
    ElMessage.error("请求使用情况数据失败");
  }
}

onMounted(() => {
  fetchUsage();
});
</script>

<style scoped>
.provider-usage-page {
  padding: 20px;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
</style>
